// pages/forgetMm/forgetMm.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userId: options.userId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  login:function(){
    wx.navigateTo({
      url: '/pages/login/login',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  //下一步
   formSubmit: function (e) {
    console.log(e)

    var that = this;
    var formData = e.detail.value;
     if (formData['LoginPassword'] == "" || formData['PassWord_2'] == "") {
      wx.showToast({
        title: '请输入新密码',
        icon: 'none'
      })
      return;
    }
     if (formData['LoginPassword'] !== formData['repassword'] || formData['PassWord_2'] !== formData['rePassWord_2']) {
       wx.showToast({
         title: '密码不一致',
         icon: 'none'
       })
       return;
     }
    // console.log(that.data.button)
    // return ;
    formData['userId'] = that.data.userId
    wx.request({
      url: app.globalData.apiUrl + 'user/findPwd2',
      data: formData,
      header: {
        'Content-Type': 'application/json'
      },
      method: 'POST',
      success: function (res) {
        if (res.data.status == 1) {
          wx.showToast({
            title: res.data.message,
            icon: 'none',

            success: function () {
              setTimeout(function () {
                wx.navigateTo({
                  url: '/pages/login/login',
                })
              }, 2000);
            }
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
       
      }
    })
  },
  blurPhone: function (e) {
    console.log(e)
    var phone = e.detail.value;
    let that = this
    if (!(/^1[34578]\d{9}$/.test(phone))) {

      this.setData({
        ajxtrue: false
      })
      if (phone.length > 11) {
        wx.showToast({
          title: '手机号有误',
          icon: 'success',
          duration: 2000
        })
      }
    } else {
      this.setData({
        ajxtrue: true,
        phone: phone,
      })
      
    }
    console.log('验证成功', that.data.ajxtrue)
  },
  //获取验证码
  get_yanzheng: function () {
    var that = this;
    if (that.data.phone == "" || that.data.ajxtrue == false) {
      wx.showToast({
        title: '手机号有误',
        icon: 'success',
        duration: 2000
      })
      return;
    } else {
      wx.request({
        url: app.globalData.apiUrl + 'User/getYzm',
        data: {
          // opt: 'getBanner',
          phone: that.data.phone
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res)

          if (res.data.status == 1) {
            wx.showToast({
              title: res.data.message,
              icon: 'none'
            })
            that.setData({
              yanzhengma: res.data.code,
            })
           
          } else {
            wx.showToast({
              title: res.data.message,
              icon: 'none'
            })
          }
        }
      })
    }
  },
})